"""
!/usr/bin/env python
-*- coding: utf-8 -*-
@Author  : MarkJia
@Site    : 
@File    : 练习1.py
"""

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains,TouchActions
from selenium.webdriver.common.keys import Keys

"""
class Testlianxi:
    def setup(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)

    def teardown(self):
        self.driver.quit()

    
    # 单击操作
    def test_case_click(self):
        self.driver.get('https://sahitest.com/demo/clicks.htm')
        # 单击操作
        ele_click = self.driver.find_element(By.CSS_SELECTOR, 'input[type="button"][value="click me"]')
        action = ActionChains(self.driver)
        action.click(ele_click)
        print('单击完成')
        action.perform()

        # 右击操作
        ele_context_click = self.driver.find_element(By.CSS_SELECTOR, 'input[type="button"][value="right click me"]')
        action.context_click(ele_context_click)
        print('右击完成')
        action.perform()

        # 双击操作
        ele_double_click = self.driver.find_element(By.CSS_SELECTOR, 'input[type="button"][value="dbl click me"]')
        action.double_click(ele_double_click)
        print('双击完成')
        action.perform()
    

    # 鼠标移动停放
    def test_move_to_element(self):
        self.driver.get('https://www.baidu.com')
        ele = self.driver.find_element(By.CSS_SELECTOR, 'span#s-usersetting-top')
        action = ActionChains(self.driver)
        action.move_to_element(ele)
        action.perform()
   

    # 鼠标拖拽
    def test_drag_drop(self):
        self.driver.get('https://sahitest.com/demo/dragDropMooTools.htm')
        ele = self.driver.find_element(By.CSS_SELECTOR, 'div.drag')
        ele1 = self.driver.find_element(By.CSS_SELECTOR, 'p>div.Item')
        action = ActionChains(self.driver)
        action.drag_and_drop(ele, ele1)
        action.perform()
 
    def test_keys(self):
        self.driver.get('https://sahitest.com/demo/label.htm')
        ele = self.driver.find_element(By.XPATH, '//label/*[@type="textbox"]')
        ele.click()
        action = ActionChains(self.driver)
        # pause ： 等待1s
        # 键盘输入 username
        action.send_keys("username").pause(1)
        # 输入空格
        action.send_keys(Keys.SPACE).pause(1)
        # 输入 tom
        action.send_keys('tom').pause(1)
        # 删除 m
        action.send_keys(Keys.BACK_SPACE).pause(1)
        action.perform()
        time.sleep(3)
"""

# class TestTouchAction:
#     def setup(self):
#         self.driver = webdriver.Chrome()
#         self.driver.maximize_window()
#         self.driver.implicitly_wait(10)
#
#     def teardown(self):
#         self.driver.quit()
#
#     def test_touchaction_scrollbottom(self):
#         """
#         1. 打开百度
#         2. 输入 selenium测试
#         3. 通过 TouchAction 方法 点击搜索框
#         4. 滑动到底部，点击下一页s
#         5. 关闭 浏览器
#         :return:
#         """
#         self.driver.get('https://www.baidu.com')
#         ele_baidu = self.driver.find_element(By.ID,'kw')
#         action = TouchActions(self.driver)
#         # 在百度输入内容
#         ele_baidu.send_keys('selenium测试')
#         # 点击搜索按钮
#         ele_search = self.driver.find_element(By.ID,'su')
#         action.tap(ele_search).perform()
#
#         # 滑动到底部
#         action.scroll_from_element(ele_baidu,0,10000).perform()
#         time.sleep(3)
#
#         # 点击下一页
#         self.driver.find_element(By.XPATH,'//*[@class="n"]').click()
#         time.sleep(3)
#
# class Testform:
#     def setup(self):
#         self.driver = webdriver.Chrome()
#         self.driver.maximize_window()
#         self.driver.implicitly_wait(10)
#
#     def teardown(self):
#         self.driver.quit()
#
#     def test_form(self):
#         self.driver.get('http://testerhome.com/account/sign_in')
#         # 登录
#         self.driver.find_element(By.CSS_SELECTOR,"#user_login").send_keys('214829112@qq.com')
#         self.driver.find_element(By.CSS_SELECTOR, "#user_password").send_keys('hogwarts')
#
#         # 点击记住密码
#         self.driver.find_element(By.ID,"user_remember_me").click()
#
#         # 提交表单操作
#         self.driver.find_element(By.XPATH,"//*[@type='submit']").click()
#
#     def test_input_file(self):
#         self.driver.get('https://image.baidu.com/')
#         # 点击按钮
#         self.driver.find_element(By.XPATH, "//*[@class='st_camera_off']").click()
#         # input 标签本地上传  <input type="file" name="images" id="stfile" size="2">
#         """
#          file_input = driver.find_element_by_name('profilePic')
#          file_input.send_keys("path/to/profilepic.gif")
#          """
#         self.driver.find_element(By.CSS_SELECTOR, "#stfile").send_keys("./images/weixin.jpg")
#         time.sleep(5)

from selenium.webdriver import ActionChains,TouchActions


class Testform:
 def setup(self):
     self.driver = webdriver.Chrome()
     self.driver.maximize_window()
     self.driver.implicitly_wait(10)

 def teardown(self):
     self.driver.quit()

 def test_form(self):
     self.driver.get('http://testerhome.com/account/sign_in')
     # 登录
     self.driver.find_element(By.CSS_SELECTOR,"#user_login").send_keys('214829112@qq.com')
     self.driver.find_element(By.CSS_SELECTOR, "#user_password").send_keys('hogwarts')

     # 点击记住密码
     self.driver.find_element(By.ID,"user_remember_me").click()

     # 提交表单操作
     self.driver.find_element(By.XPATH,"//*[@type='submit']").click()